package com.demo.com.p_c_allwait_fix;

/**
 * Desc: 消费者
 * @author: lisha 2018/7/5 9:54
 */
public class C {
    private String lock;

    public C(String lock) {
        this.lock = lock;
    }

    public void getValue() {
        try {
            synchronized (lock) {
                while (ValueObject.value.equals("")) {
                    System.out.println(" 消费者 "
                            + Thread.currentThread().getName()
                            + " waitting 了");
                    lock.wait();
                }
                System.out.println(" 消费者 "
                        + Thread.currentThread().getName()
                        + " running 了");
                System.out.println("get到的值是：" + ValueObject.value);
                ValueObject.value = "";
                // 唤醒所有线程
                lock.notifyAll();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
